//
//  RAPMainNavigationController.swift
//  COPYCAT-Weibo
//
//  Created by 闫萌 on 12/27/15.
//  Copyright © 2015 RendezvousAuParadis. All rights reserved.
//

import UIKit

class RAPMainNavigationController: UINavigationController {
    
//    override func viewDidLoad() {
//        super.viewDidLoad()
//
//    }
    
    /**
    注意，这个方法在push root view controller时也会调用
    */
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        // 对于root view controller来说，不隐藏底栏
        if viewControllers.count >= 1 {
            viewController.hidesBottomBarWhenPushed = true
        }
        
        super.pushViewController(viewController, animated: animated)

        // 从第二个控制器开始，在导航栏右边显示安奴
        if viewControllers.count >= 2 {
            viewController.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "NEXT", target: self, action: "nextButtnClicked:")
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: "navigationbar_back_withtext", title: viewControllers.first?.title, target: self, action: "backButtonClicked:")
        }
        
        // 从第三个控制器来说，在导航栏左边显示后退按钮
        if viewControllers.count >= 3 {
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: "navigationbar_back_withtext", title: "返回", target: self, action: "backButtonClicked:")
        }
    }
    
    func backButtonClicked(sender: UIBarButtonItem) {
        popViewControllerAnimated(true)
    }
    
    func nextButtnClicked(sender: UIBarButtonItem) {
        let vc = TESTVC()
        pushViewController(vc, animated: true)
        
    }

}
